<template>
    <div class="forum-comment">
        <el-dialog title="" :visible.sync="show" width="10rem">
            <h3>发评论</h3>
            <p v-if="info" class="u-line-1">回复「{{info.user_info.name}}」：{{ info.content }}</p>
            <el-input type="textarea" :rows="10" placeholder="请输入内容" v-model="content" maxlength="200" show-word-limit resize="none">
            </el-input>
            <div class="dialog-bottom">
                <div class="dialog-btn" @click="show = false">取消</div>
                <div class="dialog-btn dialog-success" @click="submitFun">评论</div>
            </div>
        </el-dialog>

    </div>
</template>

<script>
import {addComment} from "@/api/forum"
export default {
    data() {
        return {
            show: false,
            content:'',
            f_id:0,
            c_id:0,
            cc_id:0,
            info:null
        }
    },
    methods:{
        open(opt){
            this.show = true
            this.info = opt.item
            this.f_id =opt.f_id 
            this.c_id =opt.c_id || 0 
            this.cc_id =opt.cc_id || 0 
            this.content = ''

        },
        submitFun(){
            if(this.content.trim() == '') return this.$message.error('评论内容不能为空');
            addComment({content:this.content,f_id:this.f_id,c_id:this.c_id}).then(res=>{
                if(res.code == 200){
                    this.$message.success('评论成功')
                    this.show = false
                    this.$emit('submit')

                }else{
                    this.$message.error(res.msg)
                }
            })
            
        }
    }
}
</script>

<style lang="less" scoped>
.forum-comment {
    /deep/.el-dialog {
        border-radius: 0.1rem;
    }

    /deep/.el-dialog__body {
        padding: 0.875rem 0.625rem;
        ;
    }

    /deep/.el-dialog__header {
        display: none;
    }

    h3 {
        font-size: 0.3125rem;
        color: #333;
        font-weight: 600;
        margin: 0 0 0.375rem 0;
    }

    p {
        margin: 0 0 0.375rem 0;
        font-size: 0.2rem;
        color: #9695A3;
    }
    .dialog-bottom{
        display: flex;
        justify-content: center;
        align-items: center;
        padding-top: 0.6rem;
        .dialog-btn{
            display: flex;
            align-items: center;
            justify-content: center;
            width: 1.5rem;
            height: 0.5rem;
            background: #FFFFFF;
            border-radius: 0.1rem;
            border: 0.0125rem solid #9FA6C2;
            font-size: 0.2rem;
            color: #000;
            cursor: pointer;
            user-select: none;
            margin: 0 0.125rem;
        }
        .dialog-success{
            background: #4F8AF8;
            color: #fff;
            border-color: #4F8AF8;
        }
    }
}
</style>